package com.hotel.po.service;

import com.hotel.po.mapper.RoomMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class RoomService {

    @Autowired
    private RoomMapper roomMapper;

    public PageInfo<Map<String, String>> list(Long hotelId, int page, int size) {
        PageHelper.startPage(page, size);
        List<Map<String, String>> data = roomMapper.findAll(hotelId);
        return new PageInfo<>(data);
    }
    
    public PageInfo<Map<String, String>> search(String keyword, int page, int size) {
        PageHelper.startPage(page, size);
        List<Map<String, String>> data = roomMapper.search(keyword);
        return new PageInfo<>(data);
    }

    public Long create(Map<String, Object> body) {
        return roomMapper.insert(body);
    }

    public void update(Map<String, Object> body) {
        roomMapper.update(body);
    }

    public void delete(Long id) {
        roomMapper.delete(id);
    }

    public Map<String, String> findById(Long id) {
        return roomMapper.findById(id);
    }

    public Double calcSeasonPrice(Long roomId, String targetDate) {
        return roomMapper.calcSeasonPrice(roomId, targetDate);
    }
}


